package study.sort;

public class ThreadLocalTest {
	private static final ThreadLocal<Integer> threadlocal1 = new ThreadLocal<Integer>() {

		public Integer initialValue() {
			return 0;
		}
	};

	public int getNextNum() {
		threadlocal1.set(threadlocal1.get() + 1);
		return threadlocal1.get();
	}

	public static void main(String[] args) {
		ThreadLocalTest testNum = new ThreadLocalTest();
		TestClientThread thread1 = new TestClientThread(testNum);
		TestClientThread thread2 = new TestClientThread(testNum);
		TestClientThread thread3 = new TestClientThread(testNum);
		
		thread1.start();
		thread2.start();
		thread3.start();

	}

	private static class TestClientThread extends Thread {

		private ThreadLocalTest num;

		public TestClientThread(ThreadLocalTest num) {
			super();
			this.num = num;
		}

		public void run() {
			for (int i = 0; i < 3; i++) {
				System.out.println("thread[" + Thread.currentThread().getName() + "] --> sn[" + num.getNextNum() + "]");
			}
		}
	}

	/*private final ThreadLocal<Integer> threadlocal = new ThreadLocal<Integer>() {

		public Integer initialValue() {
			return 0;
		}
	};*/

	/*
	 * public class GerNum {
	 * 
	 * private static final ThreadLocal<Integer> threadlocal = new
	 * ThreadLocal<Integer>(){
	 * 
	 * public Integer initialValue() { return 0; }};
	 * 
	 * public int getNextNum(){ threadlocal.set(threadlocal.get() + 1); return
	 * threadlocal.get(); } }
	 */

}
